package gherkinedit.editors;

import org.eclipse.jface.text.rules.*;
import org.eclipse.jface.text.*;

public class GherkinScanner extends RuleBasedScanner {

	public GherkinScanner(ColorManager manager) {
		IToken comment = new Token(new TextAttribute(manager.getColor(IGherkinColorConstants.COMMENT)));
		IToken tag = new Token(new TextAttribute(manager.getColor(IGherkinColorConstants.TAG)));
		IToken keyword = new Token(new TextAttribute(manager.getColor(IGherkinColorConstants.KEYWORD)));

		IRule[] rules = new IRule[10];
		
		//Add Comment rule
		rules[0] = new EndOfLineRule("#", comment);
		//Add Tag rule
		rules[1] = new SingleLineRule("@", null, tag);
		//Add Feature rule
		rules[2] = new SingleLineRule("Feature:", " ", keyword);
		//Add Scenario
		rules[3] = new SingleLineRule("Scenario:", " ", keyword);
		//Add Given rule
		rules[4] = new SingleLineRule("Given", " ", keyword);
		//Add When rule
		rules[5] = new SingleLineRule("When", " ", keyword);
		//Add Then rule
		rules[6] = new SingleLineRule("Then", " ", keyword);
		//Add And rule
		rules[7] = new SingleLineRule("And", " ", keyword);
		//Add But rule
		rules[8] = new SingleLineRule("But", " ", keyword);
		// Add generic whitespace rule
		rules[9] = new WhitespaceRule(new GherkinWhitespaceDetector());

		setRules(rules);
	}
}
